package com.seahorse.youliao.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.seahorse.youliao.service.SysMenuService;
import com.seahorse.youliao.service.entity.SysMenuDTO;
import com.seahorse.youliao.utils.BeanUtil;
import com.seahorse.youliao.vo.request.SysMenuQueryVO;
import com.seahorse.youliao.vo.response.SysMenuPageInfoVO;
import com.seahorse.youliao.vo.response.SysMenuResponseVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
* describe: 菜单权限表
* @author : songqiang
* @date: 2020-01-17 09:23:45.259
**/
@RestController
@Api("SysMenuController")
@RequestMapping("sysMenu")
@Validated
public class SysMenuController {
	
    private static final Logger LOGGER = LoggerFactory.getLogger(SysMenuController.class);
    
	@Autowired
    private SysMenuService sysMenuService;
    /**
     * 分页查询
     * @param sysMenuQueryVO 分页查询参数
     * @return 分页参数
     */
    @ApiOperation(value = "分页查询")
    @PostMapping("getPageList")
    public SysMenuPageInfoVO selectPageList(@RequestBody @Valid SysMenuQueryVO sysMenuQueryVO) {
        String info = String.format("The method name[selectPageList] params:%s", sysMenuQueryVO.toString());
        LOGGER.info(info);
        SysMenuDTO sysMenu = BeanUtil.convert(sysMenuQueryVO, SysMenuDTO.class);

        Page<SysMenuResponseVO> page = PageHelper.startPage(sysMenuQueryVO.getPageNum(), sysMenuQueryVO.getPageSize());
        List<SysMenuDTO> sysMenuList = sysMenuService.getList(sysMenu);
        SysMenuPageInfoVO sysMenuPageInfo = new SysMenuPageInfoVO();
        BeanUtils.copyProperties(page.toPageInfo(), sysMenuPageInfo);
        List<SysMenuResponseVO> voList = BeanUtil.convert(sysMenuList, SysMenuResponseVO.class);
        sysMenuPageInfo.setList(voList);

        return sysMenuPageInfo;
    }


}
